home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: Constructor Exceptions
- Date: 2 Jan 1996 15:01:41 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4cbhcl$kst@dawn.mmm.com>
- References: <4bud9g$pv5@oxy.rust.net>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Paul Gunn (pgunn@mail.cbf.com) wrote:
-
- > I use Microsoft Visual C++, and have been gradually making use of
- > exceptions in my code. I'm interested in using exceptions in my
- > constructor code, but according to a MS article, when an exception is
- > thrown from a constructor on a heap object, the memory will not be
- > freed.
-
- > Is this behavior parculiar to the Microsoft implementation or is it
- > generally the case?
-
- It is not generally the case. Compilers that adhere to the standard
- will produce code that does not leak memory in this way.
-
- > I couldn't find any other reference to this issue in the ARM or other
- > sources. In any event, it makes me very hesitant to throw exceptions
- > from my constructors.
-
- I understand your hesitance. Exceptions are, IMHO, the best way to
- report errors from constructors and overloaded operators. If your
- compiler does not do it right, you may have to report the error in
- some other way (such as an "ok()" function) or rework your constructor
- so that it cannot fail (possibly by deferring some operations).
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-